﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RdfParser.poco;
using System.Xml;

namespace RdfParser
{
    public class RdfLoader
    {
        List<RdfClass> _clsList;

        public List<RdfClass> ClsList
        {
            get { return _clsList; }
            set { _clsList = value; }
        }

        public RdfLoader()
        {
            init();
        }

        private void init()
        {
            ClsList = new List<RdfClass>();
        }

        public void GetClasses(XmlNodeList nodeCollection)
        {

            RdfClass cls = new RdfClass();
            foreach (XmlNode n in nodeCollection)
            {
                if (n.Name.Equals("rdfs:Class"))
                {
                    // Get all information on the attributes
                    if (n.Attributes != null)
                    {
                        foreach (XmlAttribute a in n.Attributes)
                        {
                            if (a.Name.Equals("rdf:about"))
                            {
                                //Console.WriteLine("About: {0}", a.Value);
                                cls.About = a.Value;
                            }
                        }
                    }
                    if (n.ChildNodes != null)
                    {
                        foreach (XmlNode nd in n.ChildNodes)
                        {
                            if (nd.Name.Equals("rdfs:label"))
                            {
                                //Console.WriteLine("Label: {0}\n\n", nd.InnerText);
                                cls.Label = nd.InnerText;
                            }
                            if (nd.Name.Equals("rdfs:comment"))
                            {
                                //Console.WriteLine("Comment: {0}\n\n", nd.InnerText);
                                cls.Comment.Add(nd.InnerText);
                            }
                            if (nd.Name.Equals("rdfs:subClassOf"))
                            {
                                //Needs to get info from the attribute rdf:resource
                                foreach (XmlAttribute asc in nd.Attributes)
                                {
                                    if (asc.Name.Equals("rdf:resource"))
                                    {
                                        //Console.WriteLine("Subclass Resoure: {0}", asc.Value);
                                        cls.SubClassOf = asc.Value;
                                    }
                                }
                            }
                        }
                    }
                }
                GetClasses(n.ChildNodes);
            }
        }
    }
}
